import Redis from 'ioredis';

// 创建 Redis 客户端
const redisClient = new Redis();

// 发布消息到频道
async function publishMessage(channel: string, message: string) {
    try {
        // 发布消息到指定频道
        await redisClient.publish(channel, message);
        console.log(`Message "${message}" published to channel "${channel}"`);
    } catch (error) {
        console.error('Error publishing message:', error);
    }
}

// 例子
const channelName = 'myChannel';
const messageContent = 'Hello, Redis!';

// 发布消息到频道
publishMessage(channelName, messageContent);
